const db = require('../../db')

exports.allSearch = (req,res)=>{
  
    var keyword = '%'+req.query.keyword+'%'
    var searchArray = []
    // 学校通告
    var str = "select * from scharticle where title like  ? or content like ?"
    db.query(str,[keyword,keyword],(err,results)=>{
        if(err) return res.cc(err)
        
        searchArray.push(results)
        // 二手商品
        str = "select * from trade where title like  ? or content like ?"
        db.query(str,[keyword,keyword],(err,results)=>{
            if(err) return res.cc(err)
            searchArray.push(results)
            // 交流问答
            str = "select * from question where title like  ? or content like ?"
            db.query(str,[keyword,keyword],(err,results)=>{
                if(err) return res.cc(err)
                searchArray.push(results)
               
                res.send({
                    status:0,
                    data:searchArray
                })
                searchArray = []
            })
        })
    })
    
    
   
}